package com.esri.core.internal.util;

import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polyline;
import com.github.mikephil.charting.utils.Utils;
import java.io.Serializable;

/* loaded from: classes.dex */
public class e implements Serializable {
    private static final long serialVersionUID = 1;

    public static Polyline a(String str) {
        double d;
        int i;
        int indexOf;
        boolean z;
        double d2;
        boolean z2;
        double d3;
        a aVar;
        double d4;
        Point point;
        String str2 = str;
        if (str2 == null) {
            throw new IllegalArgumentException("Compressed Geometry cannot be null");
        }
        a aVar2 = new a();
        a aVar3 = new a();
        a aVar4 = new a();
        int a2 = a(str2, aVar2);
        boolean z3 = true;
        if (a2 != 0) {
            d = a2;
            i = 0;
        } else if (a(str2, aVar2) != 1) {
            throw new IllegalArgumentException("Compressed geometry: Unexpected version.");
        } else {
            i = a(str2, aVar2);
            if ((i & (-4)) != 0) {
                throw new IllegalArgumentException("Compressed geometry: Invalid flags.");
            }
            d = a(str2, aVar2);
        }
        double d5 = Utils.DOUBLE_EPSILON;
        if (i == 0) {
            indexOf = str.length();
            d3 = 0.0d;
            z = false;
            z2 = false;
        } else {
            indexOf = str2.indexOf(124);
            boolean z4 = (i & 1) == 1;
            z = (i & 2) == 2;
            if (z4) {
                aVar3.a(indexOf + 1);
                d2 = a(str2, aVar3);
            } else {
                d2 = 0.0d;
            }
            if (z) {
                aVar4.a(str2.indexOf(124, aVar3.c()) + 1);
                d5 = a(str2, aVar4);
            }
            z2 = z4;
            double d6 = d5;
            d5 = d2;
            d3 = d6;
        }
        Polyline polyline = new Polyline();
        int i2 = 0;
        int i3 = 0;
        int i4 = 0;
        int i5 = 0;
        while (aVar2.c() != indexOf) {
            int a3 = a(str2, aVar2) + i2;
            int i6 = indexOf;
            double d7 = d3;
            double d8 = a3;
            Double.isNaN(d8);
            double d9 = d8 / d;
            int a4 = a(str2, aVar2) + i3;
            boolean z5 = z3;
            double d10 = a4;
            Double.isNaN(d10);
            double d11 = d10 / d;
            if (z2) {
                aVar = aVar2;
                int a5 = a(str2, aVar3) + i4;
                d4 = d;
                double d12 = a5;
                Double.isNaN(d12);
                i4 = a5;
                point = new Point(d9, d11, d12 / d5);
            } else {
                aVar = aVar2;
                d4 = d;
                point = null;
            }
            if (z) {
                int a6 = a(str2, aVar4) + i5;
                double d13 = a6;
                Double.isNaN(d13);
                double d14 = d13 / d7;
                Point point2 = point == null ? new Point(d9, d11) : point;
                point2.setM(d14);
                point = point2;
                i5 = a6;
            }
            Point point3 = point == null ? new Point(d9, d11) : point;
            if (z5) {
                polyline.startPath(point3);
                str2 = str;
                i3 = a4;
                indexOf = i6;
                i2 = a3;
                d3 = d7;
                aVar2 = aVar;
                d = d4;
                z3 = false;
            } else {
                polyline.lineTo(point3);
                str2 = str;
                indexOf = i6;
                z3 = z5;
                i2 = a3;
                aVar2 = aVar;
                d = d4;
                i3 = a4;
                d3 = d7;
            }
        }
        return polyline;
    }

    public static boolean a(String str, String str2) {
        if (d(str) == d(str2) && c(str) == c(str2)) {
            return a(str).equals(a(str2));
        }
        return false;
    }

    public static boolean b(String str) {
        return a(str, new a()) == 0;
    }

    public static boolean c(String str) {
        a aVar = new a();
        if (a(str, aVar) != 0) {
            return false;
        }
        a(str, aVar);
        return (a(str, aVar) & 2) == 2;
    }

    public static boolean d(String str) {
        a aVar = new a();
        if (a(str, aVar) != 0) {
            return false;
        }
        a(str, aVar);
        return (a(str, aVar) & 1) == 1;
    }

    private static int a(String str, a aVar) {
        int c = aVar.c() + 1;
        boolean z = false;
        int i = 0;
        while (!z) {
            char charAt = str.charAt(c);
            if ((charAt != '+' && charAt != '-' && charAt != '|') || c == aVar.c()) {
                if (charAt >= '0' && charAt <= '9') {
                    i = ((i << 5) + Character.getNumericValue(charAt)) - Character.getNumericValue('0');
                } else if (charAt >= 'a' && charAt <= 'v') {
                    i = (((i << 5) + Character.getNumericValue(charAt)) - Character.getNumericValue('a')) + 10;
                } else {
                    throw new IllegalArgumentException("Cannot parse CompressedGeometry. Format is incorrect.");
                }
                c++;
                if (c == str.length()) {
                }
            }
            z = true;
        }
        if (c - aVar.c() > 1) {
            if (str.charAt(aVar.c()) == '-') {
                i = -i;
            } else if (str.charAt(aVar.c()) != '+') {
                throw new IllegalArgumentException("Cannot parse CompressedGeometry. Format is incorrect.");
            }
            aVar.a(c);
            return i;
        }
        return Integer.MIN_VALUE;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class a {
        private int a;

        public a() {
        }

        public a(int i) {
            this.a = i;
        }

        public void a() {
            this.a++;
        }

        public void b() {
            this.a--;
        }

        public int c() {
            return this.a;
        }

        public void a(int i) {
            this.a = i;
        }
    }
}
